import request from '@/utils/request'

const roleUrl = '/system/role'

// 获取所有的Role
export function listSysRole(data, page, size) {
  return request({
    url: `${roleUrl}/listSysRole/` + page + '/' + size,
    method: 'post',
    data: data
  })
}

export function saveSysRole(data) {
  return request({
    url: `${roleUrl}/saveSysRole`,
    method: 'post',
    data: data
  })
}

export function updateSysRole(data) {
  return request({
    url: `${roleUrl}/updateSysRole`,
    method: 'put',
    data: data
  })
}

export function delSysRole(data) {
  return request({
    url: `${roleUrl}/delSysRole`,
    method: 'delete',
    data: data
  })
}

export function listSysUserByRoleId(data, id, page, size) {
  return request({
    url: `${roleUrl}/auth/listSysUser/` + id + '/page/' + page + '/' + size,
    method: 'post',
    data: data
  })
}

export function listUnAuthSysUserByRoleId(data, id, page, size) {
  return request({
    url: `${roleUrl}/unAuth/listSysUser/` + id + '/page/' + page + '/' + size,
    method: 'post',
    data: data
  })
}

export function authSysUser(userIds, id) {
  return request({
    url: `${roleUrl}/authSysUser/` + id,
    method: 'post',
    data: userIds
  })
}

export function unAuthSysUser(userIds, id) {
  return request({
    url: `${roleUrl}/unAuthSysUser/` + id,
    method: 'delete',
    data: userIds
  })
}

export function getSysRole() {
  return request({
    url: `${roleUrl}/getSysRole`,
    method: 'get'
  })
}

export function getSysMenu(roleId) {
  return request({
    url: `${roleUrl}/getSysMenu/` + roleId,
    method: 'get'
  })
}

export function saveSysMenu(id, data) {
  return request({
    url: `${roleUrl}/saveSysMenu/` + id,
    method: 'post',
    data: data
  })
}

export default {
  listSysRole,
  saveSysRole,
  updateSysRole,
  delSysRole,
  listSysUserByRoleId,
  authSysUser,
  unAuthSysUser,
  listUnAuthSysUserByRoleId,
  getSysRole,
  getSysMenu,
  saveSysMenu
}
